using EnvDTE;

using Microsoft.WowAddonStudio.Tests.Common.Mocks;

namespace Microsoft.WowAddonStudio.Lua.RuntimeService.Tests.Common
{
	public class ConfigurationHelper
	{
		/// <summary>
		/// Initializes the service locator.
		/// </summary>
		/// <param name="locator">The locator.</param>
		public static void InitializeServiceLocator(SimpleTestServiceLocator locator)
		{
			SimpleTestServiceLocator.Register<DTE>(new MockDTE());
			SimpleTestServiceLocator.Register<EnvDTE.Project>(new MockOAProject(SimpleTestServiceLocator.Get<DTE>()));
			SimpleTestServiceLocator.Register<ProjectItem>(
				new MockProjectItem(SimpleTestServiceLocator.Get<EnvDTE.Project>(),
									SimpleTestServiceLocator.Get<DTE>(), string.Empty));

			var projectNode = new MockProjectNode(locator);
			SimpleTestServiceLocator.Register(projectNode);

			var props = ((MockProperties)SimpleTestServiceLocator.Get<ProjectItem>().Properties);
			if (!props.ContainsKey("FullPath"))
				props.Add("AddonTitle", CreateMockProperty(props, "AddonTitle", "WoWAddOn1"));

			var docs = new MockDocuments(
				SimpleTestServiceLocator.Get<DTE>(), string.Empty,
				new[] { SimpleTestServiceLocator.Get<ProjectItem>().Document });
			((MockDTE)SimpleTestServiceLocator.Get<DTE>()).SetMockDocuments(docs);
		}

		/// <summary>
		/// Gets the DTE.
		/// </summary>
		/// <value>The DTE.</value>
		protected static internal DTE DTE
		{
			get { return SimpleTestServiceLocator.Get<DTE>(); }
		}

		/// <summary>
		/// Creates the mock property.
		/// </summary>
		/// <param name="parent">The parent.</param>
		/// <param name="key">The key.</param>
		/// <param name="value">The value.</param>
		/// <returns></returns>
		private static MockProperty CreateMockProperty(Properties parent, string key, string value)
		{
			return new MockProperty(DTE, key, parent, value);
		}
	}
}